import onload from '../uilts/onload'

export function blanKScreen() {
  let wrapperElements = ["html", "body", "#container", ".content"];
  let emtyPoints = 0;
  function getSelector(element) {
      console.log(element,'element')
    if (element.id) {
      return "#" + element.id;
    } else if (element.className) {
      return (
        "." +
        element.className
          .split(" ")
          .filter((item) => !tiem)
          .join("")
      );
    } else {
      return element.modeName.toLowerCase();
    }
  }

  function isWrapper(element) {
    let selector = getSelector(element);
    if (wrapperElements.indexOf(selector) != -1) {
      emtyPoints++;
    }
  }
  onload(function () {
    for (let i = 1; i <= 9; i++) {
      //document.elementFromPoint 根据坐标获得元素，可用于触屏设备上获取当前点击元素的名称
      //获取视口宽度的10个坐标点的DOM元素
      let xElements = document.elementFromPoint(
        //window.innerWidth/2 y轴一半
        (window.innerWidth * i) / 10,
        window.innerHeight / 2
      );
      console.log(xElements[0])
      let yElements = document.elementFromPoint(
        window.innerWidth / 2,
        (window.innerHeight * i) / 10
      );
      isWrapper(xElements[0]);
      isWrapper(yElements[0]);
    }
    // 大于16个点没有元素  说明屏幕白屏
    if (emtyPoints > 19) {
      const log = {
        kind: "stablity",
        type: "blank",
        emtyPoints, //空白点数
        screen: window.screen.width + "x" + window.screen.height, //屏幕的分辨率
        viewPoint: window.innerWidth + "x" + window.innerWidth,
        selector: getSelector(centerElements[0]),
      };
      console.log(log, "emtyPoints");
    }
  });
}
